package com.liao.work.ui.activity.bmi;

import android.content.Intent;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.liao.work.R;
import com.liao.work.util.SetActionBarTitle;

public class BMIResultActivity extends AppCompatActivity {

    private ImageView img_bmi;
    private TextView tv_result;
    private TextView tv_result1;
    private TextView tv_result2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_b_m_i_result);
        SetActionBarTitle.setTitle(getSupportActionBar(), false, "健康测试");
        initView();
        Intent intent = getIntent();
        float weight = intent.getFloatExtra("weight", 0);
        float height = intent.getFloatExtra("height", 0);
        String sex = intent.getStringExtra("sex");
        if (sex.equals("男")) {
            checkBoy(weight, height);
        } else {
            checkGirl(weight, height);
        }
    }

    private void initView() {
        img_bmi = (ImageView) findViewById(R.id.img_bmi);
        tv_result = (TextView) findViewById(R.id.tv_result);
        tv_result1 = (TextView) findViewById(R.id.tv_result1);
        tv_result2 = (TextView) findViewById(R.id.tv_result2);
    }

    private void checkBoy(float weight, float height) {
        height = height / 100;
        float i = weight / (height * height);
        int image;
        String one;
        String two;
        String three;
        one = String.valueOf(i);
        float v = 18 * height * height;
        float v1 = 22 * height * height;
        float v2 = 25 * height * height;
        if (i < 18) {
            image = R.mipmap.bmi_1;
            two = "偏瘦状态";
            three = "低于" + v + "kg";
        } else if (i < 22) {
            image = R.mipmap.bmi_2;
            two = "健康状态";
            three = v + "kg - " + v1 + "kg";
        } else if (i < 25) {
            image = R.mipmap.bmi_3;
            two = "肥胖状态";
            three = v1 + "kg - " + v2 + "kg";
        } else {
            image = R.mipmap.bmi_4;
            two = "重度肥胖";
            three = "高于" + v2 + "kg";
        }
        tv_result.setText(one);
        tv_result1.setText(two);
        tv_result2.setText(three);
        img_bmi.setImageResource(image);
    }

    private void checkGirl(float weight, float height) {
        height = height / 100;
        float i = weight / (height * height);
        int image;
        String one;
        String two;
        String three;
        one = String.valueOf(i);
        float v = 16 * height * height;
        float v1 = 20 * height * height;
        float v2 = 23 * height * height;
        if (i < 16) {
            image = R.mipmap.bmi_1;
            two = "偏瘦状态";
            three = "低于" + v + "kg";
        } else if (i < 20) {
            image = R.mipmap.bmi_2;
            two = "健康状态";
            three = v + "kg - " + v1 + "kg";
        } else if (i < 23) {
            image = R.mipmap.bmi_3;
            two = "肥胖状态";
            three = v1 + "kg - " + v2 + "kg";
        } else {
            image = R.mipmap.bmi_4;
            two = "重度肥胖";
            three = "高于" + v2 + "kg";
        }
        tv_result.setText(one);
        tv_result1.setText(two);
        tv_result2.setText(three);
        img_bmi.setImageResource(image);
    }
}
